package requests

import (
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type VideoRequest struct {
	Title       string `valid:"title" json:"title"`
	Sort        int8   `valid:"sort" json:"sort"`
	Status      int8   `valid:"status" json:"status"`
	Cover       string `valid:"cover" json:"cover"`
	ZoneId      uint64 `valid:"zone_id" json:"zone_id"`
	Asname      string `valid:"asname" json:"asname"`
	Description string `valid:"description" json:"description"`
	DoubanUrl   string `valud:"douban_url" json:"douban_url"`
	Grade       int8   `json:"grade"`
}

func VideoStore(data interface{}, c *gin.Context) map[string][]string {

	rules := govalidator.MapData{
		"title":       []string{"required", "min:1", "max:20"},
		"sort":        []string{"numeric"},
		"status":      []string{"in:1,2"},
		"cover":       []string{"required"},
		"zone_id":     []string{"required"},
		"asname":      []string{"min:1", "max:20"},
		"description": []string{"required", "min:1"},
		"douban_url":  []string{"required", "url"},
	}
	messages := govalidator.MapData{
		"title": []string{
			"required:标题为必填项",
			"min:标题长度需大于 1",
			"max:标题长度需小于 20",
		},
		"sort": []string{
			"numeric:排序取值不合法",
		},
		"status": []string{
			"in:状态取值不合法",
		},
		"cover": []string{
			"required:封面为必填项",
		},
		"zone_id": []string{
			"required:区域ID为必填项",
		},
		"asname": []string{
			"min:别名长度需大于1",
			"max:别名长度需小于20",
		},
		"descriptiion": []string{
			"required:描述为必填项",
			"min:描述长度需大于1",
		},
		"douban_url": []string{
			"required:豆瓣Url为必填项",
			"url:豆瓣url格式错误",
		},
	}

	return validate(data, rules, messages)
}
